﻿using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


public partial class Main_Ledger_LedgerDetail : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = "";
    string LID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["LID"] != null)
            {
                BindLedgerMain_Tax_Details();
                BindLedgerAddress();
                BindLedgerDeliveryAddress();
                BindContactPerson();
                BindOtherDetails();
                BindRegistrationDetails();
                BindTermsandCondition();
            }
        }
    }
    protected void BindLedgerMain_Tax_Details()
    {
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTMain = DU.getdatausingprocedure("USP_ACC_GetLedger", sparam);
        if (DTMain.Rows.Count > 0)
        {
            lblLedgerName.Text = DTMain.Rows[0]["LNAME"].ToString();
            lblAltLedgerName.Text = DTMain.Rows[0]["LANAME"].ToString();
            if (DTMain.Rows[0]["ALWSUB"].ToString() == "True")
            {
                lblSubledger.Text = "YES";
                string strLed = "Select LNAME from ACC_LEDMAST Where LID='" + DTMain.Rows[0]["PLID"].ToString() + "'";
                DataTable DT1 = DU.getdata(strLed);
                if (DT1.Rows.Count > 0)
                {
                    lblGroupName.Text = DT1.Rows[0]["LNAME"].ToString();
                }
            }
            else
            {
                lblSubledger.Text = "NO";
                string strLed = "Select GNAME from ACC_GRPMAST Where GID='" + DTMain.Rows[0]["PGID"].ToString() + "'";
                DataTable DT2 = DU.getdata(strLed);
                if (DT2.Rows.Count > 0)
                {
                    lblGroupName.Text = DT2.Rows[0]["GNAME"].ToString();
                }
            }
            lblOpBalance.Text = string.Format("{0:N2}", Convert.ToDouble(DTMain.Rows[0]["ACTOPENING"].ToString()));

            strsql = "Select ACTIVE from ACC_LEDOTHERDETAILS Where LID='" + DTMain.Rows[0]["LID"].ToString() + "'";
            DataTable DT3 = DU.getdata(strsql);
            if (DT3.Rows.Count > 0)
            {
                if (DT3.Rows[0]["ACTIVE"].ToString() == "True")
                {
                    lblActive.Text = "YES";
                }
                else
                {
                    lblActive.Text = "NO";
                }
            }
            else
            {
                lblActive.Text = "NO";
            }
            lblCostCenterEffect.Text = DTMain.Rows[0]["COSTCENTREAPPLY"].ToString();
            lblSTApply.Text = DTMain.Rows[0]["STAPPLY"].ToString();
            lblTDSApply.Text = DTMain.Rows[0]["TDSAPPLY"].ToString();

            SqlParameter[] sparam1 ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
            DataTable DTTax = DU.getdatausingprocedure("USP_ACC_GetLedgerTaxDetails", sparam1);
            if (DTTax.Rows.Count > 0)
            {
                strsql = "Select TAXTYPE From ACC_TAXTYPE Where TAXTYPEID='" + DTTax.Rows[0]["TAXTYPEID"].ToString() + "'";
                DataTable DTTaxType = DU.getdata(strsql);
                if (DTTaxType.Rows.Count > 0)
                {
                    lblTaxType.Text = DTTaxType.Rows[0]["TAXTYPE"].ToString();
                }
                else
                {
                    lblTaxType.Text = "Not Apply";
                }
                strsql = "Select MAINCLASSNAME From ACC_TAXMAINCLASS Where MAINCLASSID='" + DTTax.Rows[0]["MAINCLASSID"].ToString() + "'";
                DataTable DTMainClassTax = DU.getdata(strsql);
                if (DTMainClassTax.Rows.Count > 0)
                {
                    lblTaxMainClass.Text = DTMainClassTax.Rows[0]["MAINCLASSNAME"].ToString();
                }
                else
                {
                    lblTaxMainClass.Text = "Not Apply";
                }
                strsql = "Select SUBCLASSNAME From ACC_TAXSUbCLASS Where SUBCLASSID='" + DTTax.Rows[0]["SUBCLASSID"].ToString() + "'";
                DataTable DTSubClassTax = DU.getdata(strsql);
                if (DTSubClassTax.Rows.Count > 0)
                {
                    lblTaxSubClass.Text = DTSubClassTax.Rows[0]["SUBCLASSNAME"].ToString();
                }
                else
                {
                    lblTaxSubClass.Text = "Not Apply";
                }
            }
            else
            {
                lblTaxType.Text = "Not Apply";
                lblTaxMainClass.Text = "Not Apply";
                lblTaxSubClass.Text = "Not Apply";
            }
        }
    }
    protected void BindLedgerAddress()
    {
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTAddress = DU.getdatausingprocedure("USP_ACC_GetLedgerAddressDetails", sparam);
        if (DTAddress.Rows.Count > 0)
        {

            lblAddTitle.Text = DTAddress.Rows[0]["TITLE"].ToString();
            lblAddName.Text = DTAddress.Rows[0]["LNAME"].ToString();
            lblAddress1.Text = DTAddress.Rows[0]["ADDRESS1"].ToString();
            lblAddress2.Text = DTAddress.Rows[0]["ADDRESS2"].ToString();
            lblAddress3.Text = DTAddress.Rows[0]["ADDRESS3"].ToString();
            lblAddPlace.Text = DTAddress.Rows[0]["PLACE"].ToString();
            lbladdPincode.Text = DTAddress.Rows[0]["PINCODE"].ToString();
            lblAddCountry.Text = DTAddress.Rows[0]["COUNTRY"].ToString();
            lblAddEmail.Text = DTAddress.Rows[0]["EMAIL"].ToString();
            lblAddWebsite.Text = DTAddress.Rows[0]["WEBSITE"].ToString();
            lblAddPhone.Text = DTAddress.Rows[0]["PHONE"].ToString();
            lblAddFax.Text = DTAddress.Rows[0]["FAX"].ToString();
            strsql = "Select STATENAME From MAS_State Where STATEID='" + DTAddress.Rows[0]["STATEID"].ToString() + "'";
            DataTable DTState = DU.getdata(strsql);
            if (DTState.Rows.Count > 0)
            {
                lblAddState.Text = DTState.Rows[0]["STATENAME"].ToString();
            }
        }
    }
    protected void BindLedgerDeliveryAddress()
    {
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTDelAddress = DU.getdatausingprocedure("USP_ACC_GetLedgerDeliveryAddressDetails", sparam);
        if (DTDelAddress.Rows.Count > 0)
        {

            lblDelAddTitle.Text = DTDelAddress.Rows[0]["TITLE"].ToString();
            lblDelAddName.Text = DTDelAddress.Rows[0]["CONTACTNAME"].ToString();
            lblDelAddress1.Text = DTDelAddress.Rows[0]["ADD1"].ToString();
            lblDelAddress2.Text = DTDelAddress.Rows[0]["ADD2"].ToString();
            lblDelAddress3.Text = DTDelAddress.Rows[0]["ADD3"].ToString();
            lblDelAddress4.Text = DTDelAddress.Rows[0]["ADD4"].ToString();
            lblDelAddPincode.Text = DTDelAddress.Rows[0]["PINCODE"].ToString();
            lblDelAddCountry.Text = DTDelAddress.Rows[0]["COUNTRY"].ToString();
            lblDelAddVat.Text = DTDelAddress.Rows[0]["LSTNUM"].ToString();
            if (DTDelAddress.Rows[0]["LSTDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTDelAddress.Rows[0]["LSTDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblDelAddVATDate.Text = "";
                }
                else
                {
                    lblDelAddVATDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTDelAddress.Rows[0]["LSTDATE"].ToString()));
                }
            }
           
            lblDelAddISTno.Text = DTDelAddress.Rows[0]["CSTNUM"].ToString();
            if (DTDelAddress.Rows[0]["CSTDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTDelAddress.Rows[0]["CSTDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblDelAddISTDate.Text = "";
                }
                else
                {
                    lblDelAddISTDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTDelAddress.Rows[0]["CSTDATE"].ToString()));
                }
            }
            
            lblDelAddCENVAT.Text = DTDelAddress.Rows[0]["CEPANUM"].ToString();
            if (DTDelAddress.Rows[0]["CEPADATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTDelAddress.Rows[0]["CEPADATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblDelAddCENVATDate.Text = "";
                }
                else
                {
                    lblDelAddCENVATDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTDelAddress.Rows[0]["CEPADATE"].ToString()));
                }
            }
            
            strsql = "Select STATENAME From MAS_State Where STATEID='" + DTDelAddress.Rows[0]["STATEID"].ToString() + "'";
            DataTable DTState = DU.getdata(strsql);
            if (DTState.Rows.Count > 0)
            {
                lblDelAddState.Text = DTState.Rows[0]["STATENAME"].ToString();
            }
        }
    }
    protected void BindContactPerson()
    {
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTContact = DU.getdatausingprocedure("USP_ACC_GetLedgerContactDetails", sparam);
        if (DTContact.Rows.Count > 0)
        {
            lblContactPerson.Text = DTContact.Rows[0]["PERSON"].ToString();
            lblContactPosition.Text = DTContact.Rows[0]["POSITION"].ToString();
            lblContractPhone.Text = DTContact.Rows[0]["PHONENUM"].ToString();
            lblContractMobile.Text = DTContact.Rows[0]["MOBILENUM"].ToString();
            lblContractFax.Text = DTContact.Rows[0]["FAXNUM"].ToString();
            lblContractEmail.Text = DTContact.Rows[0]["EMAIL"].ToString();
            lblContractRemarks.Text = DTContact.Rows[0]["REMARKS"].ToString();
        }
    }
    protected void BindOtherDetails()
    {
        strsql = "Select OTHSALEPERSONCAP From IVR_SETTINGS";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            lblOtherSalesPersonMain.Text = DT.Rows[0]["OTHSALEPERSONCAP"].ToString();
        }
        else
        {
            lblOtherSalesPersonMain.Text = "Sale Person";
        }
        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTOther = DU.getdatausingprocedure("USP_ACC_GetLedgerOtherDetails", sparam);
        if (DTOther.Rows.Count > 0)
        {
            lblOtherCreditPeriod.Text = DTOther.Rows[0]["CREDITPERIOD"].ToString();
            lblOtherCreditLimit.Text = string.Format("{0:N2}", Convert.ToDouble(DTOther.Rows[0]["CREDITLIMIT"].ToString()));
            lblOtherTCS.Text = DTOther.Rows[0]["TCS"].ToString();
            strsql = "Select SPRNAME From ACC_SALEsPERSON where SPRID='" + DTOther.Rows[0]["SPRID"].ToString() + "'";
            DataTable DTSaleperson = DU.getdata(strsql);
            if (DTSaleperson.Rows.Count > 0)
            {
                lblOtherSalesPerson.Text = DTSaleperson.Rows[0]["SPRNAME"].ToString();
            }
            strsql = "Select SPGNAME From ACC_SALESPRICEGROUP where SPGID='" + DTOther.Rows[0]["SPGID"].ToString() + "'";
            DataTable DTSalePrice = DU.getdata(strsql);
            if (DTSalePrice.Rows.Count > 0)
            {
                lblOtherPriceGroup.Text = DTSalePrice.Rows[0]["SPGNAME"].ToString();
            }
            strsql = "Select MAINCLASSNAME From ACC_TAXMAINCLASS Where MAINCLASSID='" + DTOther.Rows[0]["PURTAXMAINCLASSID"].ToString() + "'";
            DataTable DTPurTax = DU.getdata(strsql);
            if (DTPurTax.Rows.Count > 0)
            {
                lblOtherPurTax.Text = DTPurTax.Rows[0]["MAINCLASSNAME"].ToString();
            }
            strsql = "Select MAINCLASSNAME From ACC_TAXMAINCLASS Where MAINCLASSID='" + DTOther.Rows[0]["SALETAXMAINCLASSID"].ToString() + "'";
            DataTable DTSaleTax = DU.getdata(strsql);
            if (DTSaleTax.Rows.Count > 0)
            {
                lblOtherSaleTax.Text = DTSaleTax.Rows[0]["MAINCLASSNAME"].ToString();
            }
        }
    }
    protected void BindRegistrationDetails()
    {

        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTReg = DU.getdatausingprocedure("USP_ACC_GetRegistrationDetails", sparam);
        if (DTReg.Rows.Count > 0)
        {
            lblRegPANno.Text = DTReg.Rows[0]["PAN"].ToString();
            if (DTReg.Rows[0]["PANDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["PANDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegPANDate.Text = "";
                }
                else
                {
                    lblRegPANDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["PANDATE"].ToString()));
                }
            }
            
            lblRegTaxDeduction.Text = DTReg.Rows[0]["TDSNO"].ToString();
            if (DTReg.Rows[0]["TDSDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["TDSDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegTaxDeductionDate.Text = "";
                }
                else
                {
                    lblRegTaxDeductionDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["TDSDATE"].ToString()));
                }
            }
            
            lblRegVATTIN.Text = DTReg.Rows[0]["VATTIN"].ToString();
            if (DTReg.Rows[0]["VATTINDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["VATTINDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegVATTINDate.Text = "";
                }
                else
                {
                    lblRegVATTINDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["VATTINDATE"].ToString()));
                }
            }
            
            lblRegISTNo.Text = DTReg.Rows[0]["CSTNO"].ToString();
            if (DTReg.Rows[0]["CSTDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["CSTDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegISTNoDate.Text = "";
                }
                else
                {
                    lblRegISTNoDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["CSTDATE"].ToString()));
                }
            }
            
            lblRegSTRegNo.Text = DTReg.Rows[0]["SERTNO"].ToString();
            if (DTReg.Rows[0]["SERTNDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["SERTNDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegSTRegNoDate.Text = "";
                }
                else
                {
                    lblRegSTRegNoDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["SERTNDATE"].ToString()));
                }
            }
            
            lblRegCENVAT.Text = DTReg.Rows[0]["CEPAN"].ToString();
            if (DTReg.Rows[0]["CEPANDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["CEPANDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegCENVATDate.Text = "";
                }
                else
                {
                    lblRegCENVATDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["CEPANDATE"].ToString()));
                }
            }
            
            lblRegLuxury.Text = DTReg.Rows[0]["LTNO"].ToString();
            if (DTReg.Rows[0]["LTNDATE"].ToString() != string.Empty)
            {
                if (Convert.ToDateTime(DTReg.Rows[0]["LTNDATE"].ToString()) == Convert.ToDateTime("1/1/1900"))
                {
                    lblRegLuxuryDate.Text = "";
                }
                else
                {
                    lblRegLuxuryDate.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(DTReg.Rows[0]["LTNDATE"].ToString()));                    
                }
            }
            
            lblRegPANRef.Text = DTReg.Rows[0]["PANREF"].ToString();
        }
    }
    protected void BindTermsandCondition()
    {

        SqlParameter[] sparam ={
                                   new SqlParameter("@LID",Request.QueryString["LID"].ToString())
                               };
        DataTable DTTerm = DU.getdatausingprocedure("USP_ACC_GETLEDTERMSCONDITIONS", sparam);
        if (DTTerm.Rows.Count > 0)
        {
            lblTermsConditions.Text = DTTerm.Rows[0]["trmdesc"].ToString();
        }
    }
}
